import React, { useRef, useState } from 'react'

export default function App() {
    let [username, setUsername] = useState('atguigu');
    let [pwd, setPwd] = useState('123123');

    // 创建ref
    let usernameRef = useRef();
    let pwdRef = useRef();
    const submitHandler = (e)=>{
        e.preventDefault();
        console.log('username:' , usernameRef.current.value);
        console.log('pwd: ', pwdRef.current.value);
    }
    
    return (
        <>
            <form onSubmit={submitHandler}>
                
                <p>用户名: <input type="text" ref={usernameRef} name="username"  defaultValue={username}/></p>
                <p>密码: <input type="text" name="pwd" ref={pwdRef} defaultValue={pwd}/></p>
                <p><button>保存</button></p>
            </form>
        </>
    )
}
